package cn.jobstart.spider.downloader.request;

import cn.jobstart.common.SkMap;
import cn.jobstart.common.StringUtil;
import cn.jobstart.common.spider.LiePinToken;
import cn.jobstart.spider.TalentJob51Search;
import cn.jobstart.spider.TalentLiePinSearch;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import us.codecraft.webmagic.model.HttpRequestBody;
import us.codecraft.webmagic.utils.HttpConstant;

import java.util.Map;

/**
 * @author sunke
 * @version 1.0
 * @Description
 * @date 2023-11-13 09:43
 */
public class TalentLiePinRequest extends AbstractTalentRequest<TalentLiePinRequest, TalentLiePinSearch> {


    public LiePinToken getToken() {
        return token;
    }

    public void setToken(LiePinToken token) {
        this.token = token;
    }

    private LiePinToken token;



    private static final String URL = "https://api-lpt.liepin.com/api/com.liepin.searchfront4r.b.search";

    public TalentLiePinRequest() {
        super(URL);
        super.setMethod(method());
    }

    @Override
    public String url() {
        return URL;
    }

    /**
     * 请求方式
     *
     * @return
     */
    @Override
    public String method() {
        return HttpConstant.Method.POST;
    }

    public void addHeader(){
        if(StringUtil.isNotObjEmpty(token)&&  StringUtil.isNotObjEmpty(token.getOtherMap())){


           for(Map.Entry<String,String> entry :token.getOtherMap().entrySet()){
               addHeader(entry.getKey(),entry.getValue());
           }

        }




    }


    @Override
    public void buildExtra(TalentLiePinSearch search) {
        putExtra("pageIndex", search.getCurPage());

        Map<String,Object> map= SkMap.getInstance();

        map.put("cvSearchConditionInputVo",JSON.toJSONString(search));


        setRequestBody(HttpRequestBody.form(map, "utf-8"));




        addHeader();

    }


}
